import Axios from 'axios'
import ElementPlus, {ElMessage} from 'element-plus'
import 'element-plus/dist/index.css'
import router from './router'
import store from './store'


Axios.defaults.baseURL = "http://localhost:8080"

//前置拦截
Axios.interceptors.request.use(config =>{
    return config
})

Axios.interceptors.response.use(response =>{
        let res = response.data;

        console.log("===============")
        console.log(res)
        console.log("===============")

        if(res.code === 200){
            return response
        } else {
            ElMessage.error(response.data.message);
            return Promise.reject(response.data.message)
            //P20 12:20
        }


    },
    error => {
        console.log(error)
        if(error.response.data) {
            error.message = error.response.data.message
        }

        if(error.response.state === 401){
            store.commit("REMOVE_INFO")
            router.push("/login")
        } else {
            ElMessage.error(error.message);
            return Promise.reject(error)
        }

    }



)




